import { Role } from 'src/modules/role/entities/role.entity';
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  BeforeInsert,
  BeforeUpdate,
  JoinTable,
  ManyToMany,
} from 'typeorm';
// import { Seeding } from 'src/modules/seeding/entities/seeding.entity';
// import { Group } from 'src/modules/group/entities/group.entity';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  phone?: string;

  @Column()
  email?: string;

  @Column()
  idCard?: string;

  @Column()
  age?: number;

  @Column()
  gender?: string;

  @Column()
  address?: string;

  @Column()
  createBy: number;

  @Column()
  createTime: Date;

  @Column()
  updateBy: number;

  @Column()
  updateTime: Date;

  @Column()
  password: string;

  @Column()
  username: string;

  // @OneToMany(() => Seeding, (seeding) => seeding.player)
  // seedings: Seeding[];

  // @ManyToMany(() => Group)
  // matchGroups: Group[];

  @BeforeInsert()
  BeforeInsert() {
    this.createTime = new Date();
    this.updateTime = this.createTime;
  }

  @BeforeUpdate()
  BeforeUpdate() {
    this.updateTime = new Date();
  }

  @ManyToMany(() => Role, { cascade: true })
  @JoinTable({
    name: 'user_role',
    joinColumn: {
      name: 'user_id',
      referencedColumnName: 'id',
    },
    inverseJoinColumn: {
      name: 'role_id',
      referencedColumnName: 'id',
    },
  })
  roles?: Role[];
}
